package com.max.spark.utils

import java.io.FileInputStream
import java.util.Properties

object ConfUtil {
  val props = new Properties()

  def main(args: Array[String]): Unit = {
    val properties = props("conf/mysql.properties")
    properties.keySet().toArray().foreach { x =>
      println(x + "\t" + properties.getProperty(x.toString()))
    }
  }

  /**
   * 加载配置文件
   * @return
   */
  def props(path: String): Properties ={
    props.load(new FileInputStream(path))
    props
  }

  /**
   * 读取配置文件
   * @param path
   * @param key
   * @return
   */
  def getProperty(path: String, key: String): String ={
    val properties = props(path)
    val value = properties.getProperty(key)
    if (null == value) "" else value
  }

  /**
   * 写入配置文件
   * @param key
   * @param value
   */
  def setProperty(key: String, value: String): Unit = {
    props.setProperty(key, value)
  }
}
